{extend name="base" /}
{block name="title"}
<title>文章列表</title>
{/block}
{block name="content"}

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>文章列表 </legend> <br>
    <a href="{:url('admin/article/add')}" class="layui-btn" target="">添加文章</a>
    <a href="{:url('admin/article/index')}" class="layui-btn layui-btn-normal" target="">文章列表</a>
</fieldset>

<table class="layui-table">
    <colgroup>
        <col width="50">
        <col width="50">
        <col width="200">
        <col width="">
    </colgroup>
    <thead>
    <tr>
        <th>排序</th>
        <th>ID</th>
        <th>文章标题</th>
        <th>标签</th>
        <th>描述</th>
        <th>缩略图</th>
        <th>查看次数</th>
        <th>更新时间</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    {foreach name="list" item="v"}
    <tr>
        <td class="tc" width="10px">
            <div class="layui-anim" style="width: 50px;">
                <input type="text" onchange="changeOrder(this, {$v.id});" name="ord[]" value="{$v.art_order}" class="layui-input">
            </div>
        </td>
        <td class="tc">{$v.id}</td>
        <td>
            <a href="#">{$v.title}</a>
        </td>
        <td>{$v.tag}</td>
        <td>{$v.description}</td>
        <td>
            <img src="{$v.thumb_url}" alt="缩略图">
        </td>
        <td>{$v.view}</td>
        <td>{$v.update_time}</td>
        <td>
            <a href="{:url('/admin/article/edit/id/'. $v.id)}">修改</a>
            <a href="javascript:;" onclick="deleteAction('{$v.id}')">删除</a>
        </td>
    </tr>
    {/foreach}
    </tbody>
</table>

<div class="page_nav">
    {$list->render()}
</div>
<style type="text/css">
    .page_nav {
        overflow: hidden;
        margin: 20px auto;
    }
    .result_content ul li {
        font-size: 15px;
        float: left;
        display: list-item;
        text-align: -webkit-match-parent;
    }
    .page_nav a, .page_nav span {
        margin-right: 10px;
        padding: 5px 10px;
        float: left;
        border: 1px solid #ddd;
        border-radius: 3px;
        text-decoration: none;
    }
</style>
{/block}

{block name="js"}
<script type="text/javascript" src="/public/admin/js/jquery.min.js"></script>
<script>
    layui.use(['layer'], function(){
    });
    function changeOrder(obj, id) {
        var order = $(obj).val();
        $.post("{:url('admin/common/change_order')}",{'type':'article','id':id,'order':order,'field':'sort_order'}, function (data) {
            layer.msg(data.msg);
        },'json')
    }

    function deleteAction(id) {
        //询问框
        layer.confirm('您确定要删除这个文章吗？', {
            btn: ['确定','取消'] //按钮
        }, function(){
            //发送post请求
            $.post("{:url('admin/article/delete')}", {_method:'DELETE','_token':'csrf_token',id:id}, function (data) {
                if(data.errno) {
                    layer.msg(data.msg, {icon: 2});
                }else {
                    layer.msg('删除成功', {icon: 1});
                    location.href=location.href;
                }
            },'json');
        }, function(){
            //layer.msg('11', {icon: 2});
        });
    }
</script>
{/block}